<%@page language="java" contentType="text/html; charset=UTF-8" isELIgnored="false" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="html" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<html:header title="业务设置">
    <link rel="stylesheet" href="${baseUrl}css/public.css" media="all">
    <style type="text/css">
        .layui-form-item .layui-word-aux{
            font-size: 12px;
            color: #FF5722;
        }
        .layui-form-label{
            font-size: 12px;
        }
    </style>
    <script>

        jQuery(function () {
            layui.use(['form', 'layedit', 'laydate','element'], function(){
                var form = layui.form
                    ,layer = layui.layer
                    ,layedit = layui.layedit
                    ,laydate = layui.laydate;
                if (_businessSet.houseInOut=="true"){
                    _businessSet.houseInOut=true;
                }else{
                    _businessSet.houseInOut=false;
                }
                form.val('businessData',_businessSet);

                $("[name='inTaxRate']").blur(function () {
                    let inTaxRate = $(this).val();
                    if (inTaxRate == '') {
                        inTaxRate = '0';
                    }
                    inTaxRate = getFloat(inTaxRate,2);
                    if (inTaxRate < 0 || inTaxRate > 100) {
                        $("#inTaxRateTip").html("<i class='layui-icon layui-icon-close-fill' style='font-size: 16px;'></i>   税率必须是0-100的数字");
                        $("#inTaxRateTip").css("color","#FF5722");
                        $(this).val("0.00");
                        return;
                    }

                    $(this).val(inTaxRate);


                    post("${baseUrl}sett/businessSet/update.action",genData(),function (resp) {
                        if (resp.code == 1) {
                            $("#inTaxRateTip").html("");
                            tip("进货税率设置成功");
                        }
                    });
                });

                $("[name='saleTaxRate']").blur(function () {
                    let saleTaxRate = $(this).val();
                    if (saleTaxRate == '') {
                        saleTaxRate = '0';
                    }
                    saleTaxRate = getFloat(saleTaxRate,2);
                    if (saleTaxRate < 0 || saleTaxRate > 100) {
                        $("#saleTaxRateTip").html("<i class='layui-icon layui-icon-close-fill' style='font-size: 16px;'></i>   税率必须是0-100的数字");
                        $("#saleTaxRateTip").css("color","#FF5722");
                        $(this).val("0.00");
                        return;
                    }

                    $(this).val(saleTaxRate);

                    post("${baseUrl}sett/businessSet/update.action",genData(),function (resp) {
                        if (resp.code == 1) {
                            $("#saleTaxRateTip").html("");
                            tip("销售税率设置成功");
                        }
                    });
                });

                form.on('radio(oddFlag)', function(data){
                    post("${baseUrl}sett/businessSet/update.action",genData(), function (resp) {
                        if (resp.code == 1) {
                            tip("零头处理更新成功");
                        }
                    });
                });

                form.on('radio(numPoint)', function(data){
                    post("${baseUrl}sett/businessSet/update.action",genData(), function (resp) {
                        if (resp.code == 1) {
                            tip("数量小数位数更新成功");
                        }
                    });
                });

                form.on('radio(pricePoint)', function(data){
                    post("${baseUrl}sett/businessSet/update.action",genData(), function (resp) {
                        if (resp.code == 1) {
                            tip("价格小数位数更新成功");
                        }
                    });
                });

                form.on('checkbox(discount)', function(data){
                    processHostUpdate("销售单行折扣", genData(), data.elem.checked);
                });

                form.on('checkbox(negative)', function(data){
                    processHostUpdate("负库存销售/调拨", genData(), data.elem.checked);
                });

                form.on('checkbox(serial)', function(data){
                    processHostUpdate("商品序列号", genData(), data.elem.checked);
                });

                form.on('checkbox(saleMakeUp)', function(data){
                    processHostUpdate("销售时自动补齐金额", genData(), data.elem.checked);
                });

                form.on('checkbox(inMakeUp)', function(data){
                    processHostUpdate("进货时自动补齐金额", genData(), data.elem.checked);
                });

                form.on('checkbox(writeOff)', function(data){
                    processHostUpdate("核销功能", genData(), data.elem.checked);
                });

                form.on('checkbox(moreHouse)', function(data){
                    processHostUpdate("多仓库", genData(), data.elem.checked);
                });

                form.on('checkbox(quickPrint)', function(data){
                    processHostUpdate("快速打印", genData(), data.elem.checked);
                });

                form.on('checkbox(inTaxRateFlag)', function(data){
                    processHostUpdate("进货税率", genData(), data.elem.checked);
                });

                form.on('checkbox(saleTaxRateFlag)', function(data){
                    processHostUpdate("销售税率", genData(), data.elem.checked);
                });

                form.on('checkbox(houseInOut)', function(data){
                    processHostUpdate("出库入管理",genData(),data.elem.checked,"houseInOut");
                });


            });
        });

        function processHostUpdate(title, json,checked, field) {
            post("${baseUrl}sett/businessSet/update.action",json, function (resp) {
                if (resp.code == 1) {
                    tip(title+(checked ? "启用":"关闭")+"成功");
                } else {
                    errTip(resp.msg);
                    if (field != undefined) {
                        let json = {};
                        json[field] = !checked;
                        layui.form.val('businessData', json);
                    }
                }
            });
        }


        function genData() {
            let json = getFormJson($("#form"));
            json.negative = $('[name="negative"]').next().hasClass("layui-form-checked") ? true:false;
            json.saleMakeUp = $('[name="saleMakeUp"]').next().hasClass("layui-form-checked") ? true:false;
            json.inMakeUp = $('[name="inMakeUp"]').next().hasClass("layui-form-checked") ? true:false;
            json.quickPrint = $('[name="quickPrint"]').next().hasClass("layui-form-checked") ? true:false;
            json.houseInOut = $('[name="houseInOut"]').next().hasClass("layui-form-checked") ? true:false;
            json.inTaxRateFlag = $('[name="inTaxRateFlag"]').next().hasClass("layui-form-checked") ? true:false;
            json.saleTaxRateFlag = $('[name="saleTaxRateFlag"]').next().hasClass("layui-form-checked") ? true:false;
            return json;
        }
    </script>
</html:header>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form" method="post" action="" lay-filter="businessData" id="form">
            <input type="hidden" id="id" name="id">

            <div style="padding: 14px 0 0 4px;font-size: 16px;">基本信息</div>
            <div class="horizon-line" style="margin: 4px 0 4px 0"></div>

            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="negative" lay-filter="negative" title="允许负库存销售" value="true" lay-skin="primary">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    开启后支持无库存销售
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="saleMakeUp" lay-filter="saleMakeUp" title="销售时自动补齐实收金额  " value="true" lay-skin="primary">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    选中后，销售单自动带出实收金额
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="inMakeUp" lay-filter="inMakeUp" title="进货时自动补齐实付金额  " value="true" lay-skin="primary">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    选中后，进货单自动带出实付金额
                </div>
            </div>

<%--            <div class="layui-form-item">--%>
<%--                <label class="layui-form-label"></label>--%>
<%--                <div class="layui-input-inline">--%>
<%--                    <input type="checkbox" name="writeOff" lay-filter="writeOff" title="启用核销功能   " value="true" lay-skin="primary">--%>
<%--                </div>--%>
<%--                <div class="layui-form-mid layui-word-aux">--%>
<%--                    核销单据是为企业处理与供应商、客户之间业务交易产生的大量的往来款项而设定的，用来解决企业往来业务款项核销的。--%>
<%--                </div>--%>
<%--            </div>--%>

<%--            <div class="layui-form-item">--%>
<%--                <label class="layui-form-label"></label>--%>
<%--                <div class="layui-input-inline">--%>
<%--                    <input type="checkbox" name="moreHouse" lay-filter="moreHouse" title="销售启用多仓" value="true" lay-skin="primary">--%>
<%--                </div>--%>
<%--                <div class="layui-form-mid layui-word-aux">--%>
<%--                    开启后，销售（退货）、销售订单业务新增单据时，均支持选择多个仓库。销售订单审核后会自动锁定库存，且无库存商品可以通过预订来统计商品库存缺口。--%>
<%--                </div>--%>
<%--            </div>--%>


            <div style="padding: 14px 0 0 4px;font-size: 16px;">常用设置</div>
            <div class="horizon-line" style="margin: 4px 0 4px 0"></div>

<%--            <div class="layui-form-item">--%>
<%--                <label class="layui-form-label">零头处理</label>--%>
<%--                <div class="layui-input-block">--%>
<%--                    <input type="radio" name="oddFlag" lay-filter="oddFlag" value="1" title="抹掉零头“分”">--%>
<%--                    <input type="radio" name="oddFlag" lay-filter="oddFlag" value="2" title="抹掉零头“角”">--%>
<%--                    <input type="radio" name="oddFlag" lay-filter="oddFlag" value="3" title="抹掉零头“元”">--%>
<%--                    <input type="radio" name="oddFlag" lay-filter="oddFlag" value="4" title="不抹零">--%>
<%--                </div>--%>

<%--                <div class="layui-form-mid layui-word-aux">--%>
<%--                    针对销售订单、销售单、零售收银应收金额的零头处理--%>
<%--                </div>--%>
<%--            </div>--%>

            <div class="layui-form-item">
                <label class="layui-form-label">价格小数位数</label>
                <div class="layui-input-block">
                    <input type="radio" name="pricePoint" lay-filter="pricePoint" value="2" title="2位">
                    <input type="radio" name="pricePoint" lay-filter="pricePoint" value="3" title="3位">
                    <input type="radio" name="pricePoint" lay-filter="pricePoint" value="4" title="4位">
                </div>
            </div>


            <div class="layui-form-item">
                <label class="layui-form-label">数量小数位数</label>
                <div class="layui-input-block">
                    <input type="radio" name="numPoint" lay-filter="numPoint" value="2" title="2位">
                    <input type="radio" name="numPoint" lay-filter="numPoint" value="3" title="3位">
                    <input type="radio" name="numPoint" lay-filter="numPoint" value="4" title="4位">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="quickPrint" lay-filter="quickPrint" title="快速打印" value="true" lay-skin="primary">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    勾选后，在销售单/销售订单开单成功后，直接触发打印。
                </div>
            </div>

            <div style="padding: 14px 0 0 4px;font-size: 16px;">出入库支持</div>
            <div class="horizon-line" style="margin: 4px 0 4px 0"></div>
            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="houseInOut" lay-filter="houseInOut" title="启用出入库管理" value="true" lay-skin="primary">
                </div>
                <div class="layui-form-mid layui-word-aux">
                    开启后，销售（退货）、进货（退货）、借入借出（归还）、调拨业务都会经过待出入库流程，由仓管人员统一负责出入库管理。
                </div>
            </div>

            <div style="padding: 14px 0 0 4px;font-size: 16px;">税率支持</div>
            <div class="horizon-line" style="margin: 4px 0 4px 0"></div>

            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="inTaxRateFlag" lay-filter="inTaxRateFlag" title="启用进货税率支持" value="true" lay-skin="primary">
                </div>
                <div class="layui-input-inline">
                    <input type="number" name="inTaxRate" value="true" placeholder="默认进货税率" class="layui-input">
                </div>
                <div class="layui-form-mid">%<span id="inTaxRateTip" style="padding-left: 4px;font-size: 14px;"></span></div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label"></label>
                <div class="layui-input-inline">
                    <input type="checkbox" name="saleTaxRateFlag" lay-filter="saleTaxRateFlag" title="启用销售税率支持" value="true" lay-skin="primary">
                </div>
                <div class="layui-input-inline">
                    <input type="number" name="saleTaxRate" value="true" placeholder="默认销售税率" class="layui-input">
                </div>
                <div class="layui-form-mid">%<span id="saleTaxRateTip" style="padding-left: 4px;font-size: 14px;"></span></div>
            </div>

        </form>
    </div>
</div>
</body>
</html>